package ca.ubc.icapture.genapha.forms;

import icapture.SQLMgr;
import icapture.beans.DB.CohortPopulation;
import icapture.beans.DB.Ethnicity;
import icapture.beans.DB.Phenotypes;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.validator.Resources;

/**
 * Created by IntelliJ IDEA.
 * User: btripp
 * Date: Sep 13, 2006
 * Time: 9:39:23 AM
 * To change this template use File | Settings | File Templates.
 */
public class ExportForm extends AnalysisFilesForm
{

    // Fields: Start tab
    private ArrayList<CohortPopulation> subCohorts;
    private String[] selectedSubCohort;

    // Fields: Filter tab
    private boolean zeroIncomplete;
    private boolean zeroControls;
    private boolean hyperControls;
    private boolean caseControl;
    private boolean cleanAsthmaControls;
    private ArrayList<Ethnicity> ethnicities;
    private String[] selectedEthnicity;

    // Fields: Variables tab
    private String[] selectedSnps;
    private ArrayList<Phenotypes> covariates;
    private String[] selectedCovariates;
    private ArrayList<String> availableCutType;
    private String binarize;
    private String cutType;
    private String cutValue;

    // Fields: Format tab
    private String format;
    private boolean filePerGene;

    public ExportForm()
    {
        super();

        ArrayList<CohortPopulation> subCohortList = SQLMgr.getCohortPopulations();
        for (CohortPopulation subCohort : subCohortList)
        {
            subCohort.setPopulationName(subCohort.getCohort().getName() + "-" + subCohort.getPopulationName());
        }
        setSubCohorts(subCohortList);

        setPhenotypes(SQLMgr.getPhenotypes());
        setCovariates(SQLMgr.getPhenotypes());

        ArrayList<String> cutTypes = new ArrayList<String>();
        cutTypes.add("<=");
        cutTypes.add("<");
        cutTypes.add("=");
        cutTypes.add(">");
        cutTypes.add(">=");
        setAvailableCutType(cutTypes);
    }

    @Override
    public void reset(ActionMapping mapping, HttpServletRequest request)
    {
        setSelectedCohort(null);
        setSelectedSubCohort(null);
        setRemoveDuplicateSubjects(true);
        setRemoveMzTwins(true);
        setZeroIncomplete(false);
        setZeroControls(false);
        setHyperControls(false);
        setCaseControl(false);
        setCleanAsthmaControls(false);
        setSelectedEthnicity(null);
        setSelectedGenes(null);
        setSelectedSnps(null);
        setSelectedPhenotype(null);
        setSelectedCovariates(null);
        setFormat(null);
        setFilePerGene(false);
        setSubmitType("");
        setBinarize("none");
        setCutValue("");
    }

    @Override
    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request)
    {
        ActionErrors errors = super.validate(mapping, request);

        // Check if selected ethnicity is a valid one
        if (getSelectedEthnicity() != null)
        {
            for (int i = 0; i < getSelectedEthnicity().length; i++)
            {
                if (getSelectedEthnicity()[i].equalsIgnoreCase("-1"))
                {
                    errors.add("selectedEthnicity",
                            new ActionMessage("errors.invalid", Resources.getMessage(request, "export.ethnicity")));
                }
            }
        }

        return errors;
    }

    /**
     * @return the subCohorts
     */
    public ArrayList<CohortPopulation> getSubCohorts()
    {
        return subCohorts;
    }

    /**
     * @param subCohorts the subCohorts to set
     */
    public void setSubCohorts(ArrayList<CohortPopulation> subCohorts)
    {
        this.subCohorts = subCohorts;
    }

    /**
     * @return the selectedSubCohort
     */
    public String[] getSelectedSubCohort()
    {
        return selectedSubCohort;
    }

    /**
     * @param selectedSubCohort the selectedSubCohort to set
     */
    public void setSelectedSubCohort(String[] selectedSubCohort)
    {
        this.selectedSubCohort = selectedSubCohort;
    }

    /**
     * @return the zeroIncomplete
     */
    public boolean isZeroIncomplete()
    {
        return zeroIncomplete;
    }

    /**
     * @param zeroIncomplete the zeroIncomplete to set
     */
    public void setZeroIncomplete(boolean zeroIncomplete)
    {
        this.zeroIncomplete = zeroIncomplete;
    }

    /**
     * @return the zeroControls
     */
    public boolean isZeroControls()
    {
        return zeroControls;
    }

    /**
     * @param zeroControls the zeroControls to set
     */
    public void setZeroControls(boolean zeroControls)
    {
        this.zeroControls = zeroControls;
    }

    /**
     * @return the hyperControls
     */
    public boolean isHyperControls()
    {
        return hyperControls;
    }

    /**
     * @param hyperControls the hyperControls to set
     */
    public void setHyperControls(boolean hyperControls)
    {
        this.hyperControls = hyperControls;
    }

    /**
     * @return the caseControl
     */
    public boolean isCaseControl()
    {
        return caseControl;
    }

    /**
     * @param caseControl the caseControl to set
     */
    public void setCaseControl(boolean caseControl)
    {
        this.caseControl = caseControl;
    }

    /**
     * @return the cleanAsthmaControls
     */
    public boolean isCleanAsthmaControls()
    {
        return cleanAsthmaControls;
    }

    /**
     * @param cleanAsthmaControls the cleanAsthmaControls to set
     */
    public void setCleanAsthmaControls(boolean cleanAsthmaControls)
    {
        this.cleanAsthmaControls = cleanAsthmaControls;
    }

    /**
     * @return the ethnicities
     */
    public ArrayList<Ethnicity> getEthnicities()
    {
        return ethnicities;
    }

    /**
     * @param ethnicities the ethnicities to set
     */
    public void setEthnicities(ArrayList<Ethnicity> ethnicities)
    {
        this.ethnicities = ethnicities;
    }

    /**
     * @return the selectedEthnicity
     */
    public String[] getSelectedEthnicity()
    {
        return selectedEthnicity;
    }

    /**
     * @param selectedEthnicity the selectedEthnicity to set
     */
    public void setSelectedEthnicity(String[] selectedEthnicity)
    {
        this.selectedEthnicity = selectedEthnicity;
    }

    /**
     * @return the selectedSnps
     */
    public String[] getSelectedSnps()
    {
        return selectedSnps;
    }

    /**
     * @param selectedSnps the selectedSnps to set
     */
    public void setSelectedSnps(String[] selectedSnps)
    {
        this.selectedSnps = selectedSnps;
    }

    /**
     * @return the covariates
     */
    public ArrayList<Phenotypes> getCovariates()
    {
        return covariates;
    }

    /**
     * @param covariates the covariates to set
     */
    public void setCovariates(ArrayList<Phenotypes> covariates)
    {
        this.covariates = covariates;
    }

    /**
     * @return the selectedCovariates
     */
    public String[] getSelectedCovariates()
    {
        return selectedCovariates;
    }

    /**
     * @param selectedCovariates the selectedCovariates to set
     */
    public void setSelectedCovariates(String[] selectedCovariates)
    {
        this.selectedCovariates = selectedCovariates;
    }

    /**
     * @return the availableCutType
     */
    public ArrayList<String> getAvailableCutType()
    {
        return availableCutType;
    }

    /**
     * @param availableCutType the availableCutType to set
     */
    public void setAvailableCutType(ArrayList<String> availableCutType)
    {
        this.availableCutType = availableCutType;
    }

    /**
     * @return the binarize
     */
    public String getBinarize()
    {
        return binarize;
    }

    /**
     * @param binarize the binarize to set
     */
    public void setBinarize(String binarize)
    {
        this.binarize = binarize;
    }

    /**
     * @return the cutType
     */
    public String getCutType()
    {
        return cutType;
    }

    /**
     * @param cutType the cutType to set
     */
    public void setCutType(String cutType)
    {
        this.cutType = cutType;
    }

    /**
     * @return the cutValue
     */
    public String getCutValue()
    {
        return cutValue;
    }

    /**
     * @param cutValue the cutValue to set
     */
    public void setCutValue(String cutValue)
    {
        this.cutValue = cutValue;
    }

    /**
     * @return the format
     */
    public String getFormat()
    {
        return format;
    }

    /**
     * @param format the format to set
     */
    public void setFormat(String format)
    {
        this.format = format;
    }

    /**
     * @return the filePerGene
     */
    public boolean isFilePerGene()
    {
        return filePerGene;
    }

    /**
     * @param filePerGene the filePerGene to set
     */
    public void setFilePerGene(boolean filePerGene)
    {
        this.filePerGene = filePerGene;
    }
}
